package com.xgzit.xgzmall.search.controller;

import com.sun.media.jfxmedia.logging.Logger;
import com.xgzit.xgzmall.search.service.MallSearchService;
import com.xgzit.xgzmall.search.vo.SearchParamVo;
import com.xgzit.xgzmall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author xgz
 * @Date 2021-04-25 23:06
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;
    /**
    * 参数太多，利用SpringMvc进行自动封装
    * @param param:
    * @return java.lang.String
    */
    @GetMapping("/list.html")
    public String listPage(SearchParamVo param, Model model, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());
        // 接收所有检索条件，去es中搜索，并返回结果。
        SearchResultVo vo =  mallSearchService.search(param);
        model.addAttribute("result", vo);
        return "list";
    }
}
